草庐IT

sql - MongoDB : few questions

全部标签

sql - gorp: "auto_increment"附近:语法错误

我正在尝试编写简单的程序以使用gorp将行插入表中,但在创建表时出现错误。代码如下:packagemainimport_"github.com/mattn/go-sqlite3"import"database/sql"import"fmt"import"github.com/go-gorp/gorp"funcmain(){typePersonstruct{Identiint64Createdint64FNamestringLNamestring}db,_:=sql.Open("sqlite3","mydb.db")dbmap:=&gorp.DbMap{Db:db,Dialect:gor

mongodb - 在golang mgo中让字段空白

我正在尝试将beego与mongo结合使用。你可以在以下位置找到我的来源:https://github.com/wsourabh/bapi但是在调用v1/账户/:id我总是得到这样的回应curl-vlocalhost:8080/v1/accounts/0df542560fbfc39a4bdb24d0ca44d37e*Trying127.0.0.1...*Connectedtolocalhost(127.0.0.1)port8080(#0)>GET/v1/accounts/0df542560fbfc39a4bdb24d0ca44d37eHTTP/1.1>Host:localhost:80

mongodb - 访问 map 时的 Goroutine block

以下代码片段取自旨在从MongoDB读取文档并将其写入Postgres数据库的程序。该程序是使用生产者/消费者模式实现的:生产者Goroutine从Mongo读取并将获取的文档发送到channel。consumerGoroutine从channel中读取数据,构造一个INSERTINTOsql语句并将数据插入到Postgres数据库中。不幸的是,消费者似乎不确定地阻止。我相信当访问从producer到consumer的chan传递的map数据结构时,就会发生这种情况,但不能确定。生产者的简化代码:funcproducer(opschanBatchOp,...){//Iterateove

sql - 执行查询 sql 时出错 - Golang

我尝试使用来自golang的原生sqlapi在Golang中执行此查询。typeDBstruct{*sql.DB}typeIUserinterface{CreateUserTable()(sql.Result,error)}//InitDBinitializesthedatabasefuncInitDB()*DB{db,err:=sql.Open(dbDriver,dbName)iferr!=nil{log.Fatal("failedtoinitializedatabase:",err)}err2:=db.Ping()iferr2!=nil{log.Fatal(err2)}//vard

mongodb - 有没有办法通过 Find() 获取 slice ?

现在我在做:sess:=mongodb.DB("mybase").C("mycollection")varusers[]struct{Usernamestring`bson:"username"`}err=sess.Find(nil).Select(bson.M{"username":1,"_id":0}).All(&users)iferr!=nil{fmt.Println(err)}varmyUsers[]stringfor_,user:=rangeusers{myUsers=append(myUsers,user.Username)}有没有更有效的方法直接从Find(或其他搜索函数

sql - 一行的多个条件如果不存在则返回 NULL postgresql

我有这样的架构:[ad_id].[name].[valueofname]1.name."brian"1.age."23"2.job."IT"2.name."Jack"行名称包含多个值:年龄、姓名、生日、工作、年龄我想将其转换为:[ad_id].[name].[age].[birthday].[job][valueofad_id][valueofname][valueofnameofage][valueofnameofbirth][valueofnameofjob]我在下面做了这个查询选择来修复它,所以在我的程序中我必须得到结果ad_id='xxxx'代表每个whenname='name

mongodb - 如何编码/解码 mongodb 游标?

我需要建立一个“页面”列表,所以其中一部分会有一个cursor.问题是我找不到编码(到字符串)和解码光标的方法。任何的想法?Cursor接口(interface)没有“编码”方法(有ID,但未记录)并且无法从字符串(或int)创建新游标。typeCursorinterface{//GettheIDofthecursor.ID()int64//Getthenextresultfromthecursor.//Returnstrueiftherewerenoerrorsandthereisanextresult.Next(context.Context)boolDecode(interfac

mongodb - golang 中的聚合查询

关闭。这个问题需要更多focused.它目前不接受答案。想改进这个问题吗?更新问题,使其只关注一个问题editingthispost.关闭4年前。Improvethisquestion我需要用mgo在golang中编写一个查询,这是在mongo中的查询:db.some.aggregate([{$match:{"data.id":"11111"}},{$project:{_id:0,url:{$concat:["https://www.someurl.com/","$data.aID"]},items:{"$map":{"input":"$data.items","as":"it","i

sql - 无法将日期时间纪元转换为仅日期纪元格式

我正在尝试从一个DB(db1)获取日期格式的日期(“jobDate”),然后插入到另一个DB(db2),其中Date(“resolvedDate”)为纪元格式。现在我将日期从db1传递到db2的选择查询。为了匹配它们的数据类型,我将time.Time转换为纪元格式并传递给db2。我不需要时间戳,只需要YYYY-MM-DD格式。但这里的问题是,来自db2的纪元日期包含日期和时间。结果,当我将jobDate传递给select查询时,它无法匹配resolvedDate中的任何条目。我的代码如下:dsn:="server=********.md3q.***.com;userid=*******

mongodb - 无法解析行 #126 : mongo. 数据库 = mongo_db_test

我正在学习本教程Golang+Revelwebframework+MongodbRESTFulgeneratorfor(revel_mgo)一步一步来,但是当我最终结束它并尝试运行它时,它抛出了这个错误CRIT16:11:18revel_container.go:139:无法加载配置文件error="C:\Users\Userx\go\src\RevelApp\conf\app.conf:无法解析第126行:mongo.database=RevelApp"第126行是这样的:[dev]126-mongo.database=mongo_db_test127-mongo.path=127.